﻿
<?php
// 本文档自动生成，仅供测试运行
import("@.Public.UserCheck");//验证用户是否登录类
class UserManageAction extends Action
{
//登录操作
	public function login()
	{
		if(isset($_POST['submit']))//验证信息并跳转
		{
			
			$user=M('User');
			$condition['username']=$_POST['username'];
			$condition['password']=$_POST['password'];
			$list=$user->where($condition)->select();
			if(!empty($list))
			{
				$_SESSION['username']=$list[0]['username'];
				
				//$_SESSION['username']=$_POST['username'];
				//$this->assign('name',$str);
				//$this->assign('mes','成功登录');
				$this->redirect('Index/index');
			}
			else
			{
				$this->assign('mes','用户名或密码错误，请重新登录');
				$this->display();
			}
			
		}
		else//显示登录表单
		{
			
			$this->display();
		}
	}
	//注册操作
	public function register()
	{
		if(isset($_POST['submit']))//验证信息并跳转
		{
				
			$user=M('User');
			$con['username']=$_POST['username'];
			if($user->create())
			{
				if(!preg_match('/^[\w\x80-\xff]{3,15}$/', $user->username))
				{
					$this->assign('mes','用户名不符合规则，请重新填写！');
				}
				else if($user->where($con)->select())
				{
					$this->assign('mes','该用户名已经被人使用了！');
				}
				else if(strlen($user->password)<6)
				{
					$this->assign('mes','请使用不少于6位的密码！');
				}
				else if($_POST['password']!=$_POST['repassword'])
				{
					$this->assign('mes','两次密码不一样！');
				}
				//else if(!preg_match('/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/', $user->email))
				//{
				//	$this->assign('mes','请使用正确的电子邮件！');
				//}
				else if($user->add())
				{
					$this->redirect('login');
				}
				
				$this->display();
				
			}
			else
			{
				$this->assign('mes','用户名或密码错误，请重新登录');
				$this->display();
			}
		}
		else//显示注册表单
		{
				
			$this->display();
		}
	}
	
	
	//登出操作
	public function logout()
	{
		unset($_SESSION['username']);
		$this->redirect('Index/index');
	}
}
?>